load moviedata;


M = 3952;
N = 6040;
D = 20;

u_ind   = train_vec(:,1);
m_ind   = train_vec(:,2);
rating  = train_vec(:,3);

if restart == 1
    restart = 0;
    
    f_u = cell(1,N);
    f_v = cell(1,M);
    
    fprintf('building index ...\n');
    for i = 1:N
        f_u{i}.jj = m_ind(u_ind == i);
        f_u{i}.val = rating(u_ind == i);
    end
    
    for j = 1:M
        f_v{j}.ii = u_ind(m_ind == j);
        f_v{j}.val = rating(m_ind == j);
    end
    
    save('filter.mat','f_u','f_v');
else
    load filter;
end

U = 0.1*randn(D,N);
V = 0.1*randn(D,M);

dim.D = D; 
dim.N = N; 
dim.M = M;

filter.f_u  = f_u;
filter.f_v  = f_v;